package com.bbz.crawler.core.proxyip.dataprocess;

import java.util.ArrayList;
import java.util.List;

import com.bbz.crawler.core.commen.model.CrawlerProxyIp;

import us.codecraft.webmagic.Page;

public class Ip3366DataProcess {

	public List<CrawlerProxyIp> dataProcess(Page page) {
		List<String> ipInfo = page.getHtml()
				.xpath("//table[@class='table table-bordered table-striped']/tbody/tr/td/text()").all();
		List<CrawlerProxyIp> ipList = new ArrayList<>();

		int count = ipInfo.size() / 8;
		for (int i = 0; i < count; i++) {
			CrawlerProxyIp crawlerProxyIp = new CrawlerProxyIp();
			crawlerProxyIp.setIp(ipInfo.get(i * 8));
			crawlerProxyIp.setPort(ipInfo.get(i * 8 + 1));
			crawlerProxyIp.setType(ipInfo.get(i * 8 + 3));
			crawlerProxyIp.setIpaddress(ipInfo.get(i * 8 + 5));
			ipList.add(crawlerProxyIp);
		}
		return ipList;
	}

}
